<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title></title>
    <link rel="stylesheet" type="text/css" href="../../../../static/layui/css/layui.css"/>
    <script src="../../../../static/layui/layui.js"></script>
    <style type="text/css">

    </style>
</head>

<body style="padding: 30px;padding-left: 0;">
<form id="myform" class="layui-form">
    {{{if $parent_id}}}
        <input type="hidden" name="parent_id" value="{{{$parent_id}}}"/>
        <div class="layui-form-item">
            <label class="layui-form-label">所属数据表</label>
            <div class="layui-input-block">
                <select name="table_name">
                    <option value="">无选择</option>
                    {{{foreach from=$tables item=table}}}
                        <option value="{{{$table.Tables_in_fastphp_test}}}">{{{$table.Tables_in_fastphp_test}}}</option>
                    {{{/foreach}}}
                </select>
            </div>
        </div>
    {{{else}}}
        <div class="layui-form-item">
            <label class="layui-form-label">所属父菜单</label>
            <div class="layui-input-block">
                <select name="parent_id">
                    <option value="0">无选择</option>
                    {{{foreach from=$parents item=parent}}}
                        <option value="{{{$parent.id}}}">{{{$parent.name}}}</option>
                    {{{/foreach}}}
                </select>
            </div>
        </div>
    {{{/if}}}
    <div class="layui-form-item">
        <label class="layui-form-label">菜单名</label>
        <div class="layui-input-block">
            <input type="text" name="name" placeholder="请输入菜单名" class="layui-input" lay-verify="required">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">菜单地址</label>
        <div class="layui-input-block">
            <input type="text" name="url" placeholder="请输入菜单地址" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">排序</label>
        <div class="layui-input-block">
            <input type="number" name="order_num" placeholder="请输入排序" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">状态</label>
        <div class="layui-input-block">
            <input type="radio" name="status" value="1" title="开启" checked>
            <input type="radio" name="status" value="0" title="关闭">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="*">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>

<script type="text/javascript">
    layui.use(['form','upload'], function () {
        form = layui.form
        var $ = layui.jquery

        form.on('submit(*)', function(data){
            console.log(data.elem) //被执行事件的元素DOM对象，一般为button对象
            console.log(data.form) //被执行提交的form对象，一般在存在form标签时才会返回
            console.log(data.field) //当前容器的全部表单字段，名值对形式：{name: value}

            $.post('add', data.field, function (res) {
                console.log(res)
                if (res.code === 200) {
                    layer.msg(res.msg, {icon: 1})
                    setTimeout(function () {
                        // var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        // parent.layer.close(index); //再执行关闭
                        parent.location.reload()
                    }, 1000)
                } else {
                    layer.msg(res.msg || '请求失败', {icon: 2});
                }
            }, 'json')
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
    });
</script>

</body>
</html>